home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Mops source
/
PPC source
/
pBytestring
< prev
next >
Wrap
Text File
|
1998-08-01
|
3KB
|
163 lines
(*
The class Bytestring adds further methods to the class String+, aimed
mainly at managing strings of bytes which are arbitrary data, not
just ascii characters, and may contain non-aligned 16- or 32-bit
quantities. (Some of the fields in PEF files are good examples.)
These methods allow various numbers of bytes to be fetched from
or stored to the current position of the string, with the current
position being updated.
*)
:class BYTESTRING super{ string }
:m 1stW: \ ( -- n )
^1st: self w@ ;m
:m 1stL: \ ( -- n )
^1st: self @ ;m
:m >1st: \ ( c -- )
^1st: self c! ;m
:m >1stW: \ ( n -- )
^1st: self w! ;m
:m >1stL:
^1st: self ! ;m
:m nxtC: \ ( -- c )
1st: self 1 skip: self ;m
:m nxtW: \ ( -- n )
1stW: self 2 skip: self ;m
:m NXTL: \ ( -- n )
1stL: self 4 skip: self ;m
:m NXTN: { n -- n' }
get: self n >=
IF 0 swap n bounds DO 8 << i c@ or LOOP
n skip: self
ELSE drop 0
THEN ;m
:m >NXTC: \ ( c -- )
>1st: self 1 skip: self ;m
:m >NXTW: \ ( n -- )
>1stW: self 2 skip: self ;m
:m >NXTL: \ ( n -- )
>1stL: self 4 skip: self ;m
:m >NXT$: \ ( addr len -- )
ovwr: self ;m
:m >NXTN: { val n -- }
val pad !
4 n - pad + n >nxt$: self ;m
:m +C: \ ( c -- )
+: self ;m
:m +W: \ ( n -- )
pad w! pad 2 add: self ;m
:m +L: \ ( n -- )
pad ! pad 4 add: self ;m
:m +N: { n cnt -- }
n 32 cnt 2* 4* - << pad !
pad cnt add: self ;m
;class
:class BYTESTRING_ARRAY super{ bytestring array }
int CURRENT
:m CURRENT:
get: current ;m
:m (SEL): { idx -- }
idx put: current
idx ^elem4 @ ^base !
nil?: self ?EXIT
^base size: handle put: size ;m
:m SELECT: { idx -- }
idx (sel): self
nil?: self
IF \ new: not done - do it now
new: super
handle: self idx ^elem4 !
ELSE
reset: self
THEN ;m
:m NEW: ;m \ Not needed now, as select: does it if necessary.
:m RELEASE:
limit 0 DO
i (sel): self release: super \ Harmless if not open
nilH i ^elem4 !
LOOP ;m
:m CLEARALL:
limit 0 DO
i (sel): self
handle: self IF clear: super THEN
LOOP ;m
:m DUMP:
." Current:" get: current . cr
dump: super ;m
:m CLASSINIT:
idxbase limit 4* bounds
DO nilH i ! 4 +LOOP ;m
;class
endload
\ =========== the current test block ============
: selectTest
SELECT[ 1 ]=>
[ 2 ]=>
[ 3 ]=> 23
[ 6 ]=> 200 200 dump
[ 9 ]=> 99 88 77
DEFAULT=> 1234
]SELECT
;
:f TEST { \ x -- }
dbgr
cr cr ." hi there one and all!" cr 1 2 3
begin
query cr
begin
rest nip 0>
while
defined?
if execute
else
number selectTest
then
repeat
.s cr
again
;f
:f quit test ;f \ temp so we can catch errors!